/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RealizarTestFrame.java
 *
 * Created on 09-ene-2012, 12:35:40
 */
package occho.view;

import java.awt.Color;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;
import occho.data.OracleAsignaturaDAO;
import occho.model.Asignatura;
import occho.model.FachadaRealizarTest;
import occho.model.Test;
import occho.model.Usuario;
import occho.view.resources.Messages;

/**
 *
 * @author inftel
 */
public class RealizarTestFrame extends javax.swing.JInternalFrame implements Internacionalizable {

    private Usuario usuario;
    private OcchoView view;
    private DefaultMutableTreeNode ultimoNodo;
    private FachadaRealizarTest fachadaTest;
    private List<Asignatura> asignaturas;

    /** Creates new form RealizarTestFrame
     * @param view 
     * @throws SQLException
     * @throws ClassNotFoundException  
     */
    public RealizarTestFrame(OcchoView view) throws SQLException, ClassNotFoundException {

        initComponents();

        this.usuario = view.getUsuario();
        this.view = view;
        this.fachadaTest = new FachadaRealizarTest();
        
        this.asignaturas = this.fachadaTest.getAsignaturas();
        setLenguaje();

    }

    private void loadTree() {

        DefaultMutableTreeNode asignatura = null;
        DefaultMutableTreeNode test = null;
        
        DefaultMutableTreeNode top = new DefaultMutableTreeNode(Messages.getString("rootNode.text", Messages.BUNDLE_NAME_REALIZAR_TEST));

        for (Asignatura asig : asignaturas) {
            asignatura = new DefaultMutableTreeNode(asig);
            top.add(asignatura);

            for (Test tes : asig.getTests()) {
                test = new DefaultMutableTreeNode(tes);
                asignatura.add(test);

            }
        }

        DefaultTreeModel modelo = new DefaultTreeModel(top);

        this.testTree.setModel(modelo);
        this.testTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        realizarTestButton = new javax.swing.JButton();
        actualizarButton = new javax.swing.JButton();
        testScrollPane = new javax.swing.JScrollPane();
        testTree = new javax.swing.JTree();
        informacionPanel = new javax.swing.JPanel();
        fechaInicioLabel = new javax.swing.JLabel();
        fechaInicioLabel1 = new javax.swing.JLabel();
        horaFinLabel1 = new javax.swing.JLabel();
        HoraFinLabel = new javax.swing.JLabel();
        horaInicioLabel1 = new javax.swing.JLabel();
        HoraInicioLabel = new javax.swing.JLabel();
        fechaFinLabel = new javax.swing.JLabel();
        fechaFinLabel1 = new javax.swing.JLabel();
        descripcionLabel = new javax.swing.JLabel();
        descripcionLabel1 = new javax.swing.JLabel();
        numeroPreguntasLabel = new javax.swing.JLabel();
        numeroPreguntasLabel1 = new javax.swing.JLabel();
        consejoPanel = new javax.swing.JPanel();
        consejoTextField = new javax.swing.JTextField();

        setClosable(true);
        setMaximumSize(new java.awt.Dimension(10000, 10000));
        setMinimumSize(new java.awt.Dimension(850, 500));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(850, 500));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(occho.OcchoApp.class).getContext().getResourceMap(RealizarTestFrame.class);
        realizarTestButton.setText(resourceMap.getString("realizarTestButton.text")); // NOI18N
        realizarTestButton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        realizarTestButton.setName("realizarTestButton"); // NOI18N
        realizarTestButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                realizarTestButtonActionPerformed(evt);
            }
        });

        actualizarButton.setText(resourceMap.getString("actualizarButton.text")); // NOI18N
        actualizarButton.setName("actualizarButton"); // NOI18N
        actualizarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actualizarButtonActionPerformed(evt);
            }
        });

        testScrollPane.setName("testScrollPane"); // NOI18N

        testTree.setBackground(resourceMap.getColor("testTree.background")); // NOI18N
        testTree.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("testTree.border.title"))); // NOI18N
        testTree.setForeground(getBackground());
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        testTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        testTree.setName("testTree"); // NOI18N
        testTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                testTreeValueChanged(evt);
            }
        });
        testScrollPane.setViewportView(testTree);

        informacionPanel.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        informacionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("informacionPanel.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, resourceMap.getColor("informacionPanel.border.titleColor"))); // NOI18N
        informacionPanel.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        informacionPanel.setName("informacionPanel"); // NOI18N

        fechaInicioLabel.setText(resourceMap.getString("fechaInicioLabel.text")); // NOI18N
        fechaInicioLabel.setName("fechaInicioLabel"); // NOI18N

        fechaInicioLabel1.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        fechaInicioLabel1.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        fechaInicioLabel1.setText(resourceMap.getString("fechaInicioLabel1.text")); // NOI18N
        fechaInicioLabel1.setName("fechaInicioLabel1"); // NOI18N

        horaFinLabel1.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        horaFinLabel1.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        horaFinLabel1.setText(resourceMap.getString("horaFinLabel1.text")); // NOI18N
        horaFinLabel1.setName("horaFinLabel1"); // NOI18N

        HoraFinLabel.setText(resourceMap.getString("HoraFinLabel.text")); // NOI18N
        HoraFinLabel.setName("HoraFinLabel"); // NOI18N

        horaInicioLabel1.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        horaInicioLabel1.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        horaInicioLabel1.setText(resourceMap.getString("horaInicioLabel1.text")); // NOI18N
        horaInicioLabel1.setName("horaInicioLabel1"); // NOI18N

        HoraInicioLabel.setText(resourceMap.getString("HoraInicioLabel.text")); // NOI18N
        HoraInicioLabel.setName("HoraInicioLabel"); // NOI18N

        fechaFinLabel.setText(resourceMap.getString("fechaFinLabel.text")); // NOI18N
        fechaFinLabel.setName("fechaFinLabel"); // NOI18N

        fechaFinLabel1.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        fechaFinLabel1.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        fechaFinLabel1.setText(resourceMap.getString("fechaFinLabel1.text")); // NOI18N
        fechaFinLabel1.setName("fechaFinLabel1"); // NOI18N

        descripcionLabel.setText(resourceMap.getString("descripcionLabel.text")); // NOI18N
        descripcionLabel.setName("descripcionLabel"); // NOI18N

        descripcionLabel1.setBackground(resourceMap.getColor("descripcionLabel1.background")); // NOI18N
        descripcionLabel1.setForeground(resourceMap.getColor("horaInicioLabel1.foreground")); // NOI18N
        descripcionLabel1.setText(resourceMap.getString("descripcionLabel1.text")); // NOI18N
        descripcionLabel1.setName("descripcionLabel1"); // NOI18N

        numeroPreguntasLabel.setText(resourceMap.getString("numeroPreguntasLabel.text")); // NOI18N
        numeroPreguntasLabel.setName("numeroPreguntasLabel"); // NOI18N

        numeroPreguntasLabel1.setName("numeroPreguntasLabel1"); // NOI18N

        javax.swing.GroupLayout informacionPanelLayout = new javax.swing.GroupLayout(informacionPanel);
        informacionPanel.setLayout(informacionPanelLayout);
        informacionPanelLayout.setHorizontalGroup(
            informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, informacionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(informacionPanelLayout.createSequentialGroup()
                        .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(fechaInicioLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(numeroPreguntasLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(fechaFinLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(HoraFinLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(HoraInicioLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE))
                        .addGap(18, 18, 18))
                    .addGroup(informacionPanelLayout.createSequentialGroup()
                        .addComponent(descripcionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fechaFinLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                    .addComponent(fechaInicioLabel1)
                    .addComponent(horaFinLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                    .addComponent(horaInicioLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                    .addComponent(numeroPreguntasLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                    .addComponent(descripcionLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        informacionPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {HoraFinLabel, HoraInicioLabel, descripcionLabel, fechaFinLabel, fechaInicioLabel, numeroPreguntasLabel});

        informacionPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {descripcionLabel1, fechaFinLabel1, fechaInicioLabel1, horaFinLabel1, horaInicioLabel1, numeroPreguntasLabel1});

        informacionPanelLayout.setVerticalGroup(
            informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(informacionPanelLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(descripcionLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(descripcionLabel))
                .addGap(18, 18, 18)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numeroPreguntasLabel)
                    .addComponent(numeroPreguntasLabel1))
                .addGap(18, 18, 18)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fechaInicioLabel)
                    .addComponent(fechaInicioLabel1))
                .addGap(18, 18, 18)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fechaFinLabel)
                    .addComponent(fechaFinLabel1))
                .addGap(18, 18, 18)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(HoraInicioLabel)
                    .addComponent(horaInicioLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(informacionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(HoraFinLabel)
                    .addComponent(horaFinLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(53, Short.MAX_VALUE))
        );

        informacionPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {HoraFinLabel, HoraInicioLabel, descripcionLabel, fechaFinLabel, fechaInicioLabel, numeroPreguntasLabel});

        informacionPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {descripcionLabel1, fechaFinLabel1, fechaInicioLabel1, horaFinLabel1, horaInicioLabel1, numeroPreguntasLabel1});

        consejoPanel.setBorder(javax.swing.BorderFactory.createLineBorder(resourceMap.getColor("consejoPanel.border.lineColor"))); // NOI18N
        consejoPanel.setName("consejoPanel"); // NOI18N

        consejoTextField.setBackground(getBackground());
        consejoTextField.setFont(resourceMap.getFont("consejoTextField.font")); // NOI18N
        consejoTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        consejoTextField.setText(resourceMap.getString("consejoTextField.text")); // NOI18N
        consejoTextField.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        consejoTextField.setName("consejoTextField"); // NOI18N

        javax.swing.GroupLayout consejoPanelLayout = new javax.swing.GroupLayout(consejoPanel);
        consejoPanel.setLayout(consejoPanelLayout);
        consejoPanelLayout.setHorizontalGroup(
            consejoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, consejoPanelLayout.createSequentialGroup()
                .addContainerGap(106, Short.MAX_VALUE)
                .addComponent(consejoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(79, 79, 79))
        );
        consejoPanelLayout.setVerticalGroup(
            consejoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(consejoPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(consejoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(testScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(consejoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(informacionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(actualizarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(realizarTestButton)
                        .addGap(50, 50, 50))))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {actualizarButton, realizarTestButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(testScrollPane, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(consejoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(informacionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(realizarTestButton, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(actualizarButton))
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void actualizarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actualizarButtonActionPerformed

    this.descripcionLabel1.setText("");
    this.numeroPreguntasLabel1.setText("");
    this.fechaInicioLabel1.setText("");
    this.fechaFinLabel1.setText("");
    this.horaInicioLabel1.setText("");
    this.horaFinLabel1.setText("");

    try {
        asignaturas = fachadaTest.getAsignaturas();
        loadTree();
    } catch (SQLException ex) {
        Logger.getLogger(RealizarTestFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(RealizarTestFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    //view.setStatusMessageLabel("Asignaturas y tests actualizados.", Color.black);
    JOptionPane.showMessageDialog(null, Messages.getString("actualizarMensaje", Messages.BUNDLE_NAME_REALIZAR_TEST));

}//GEN-LAST:event_actualizarButtonActionPerformed

private void testTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_testTreeValueChanged

    ultimoNodo = (DefaultMutableTreeNode) testTree.getLastSelectedPathComponent();
    mostrarInformacion();
}//GEN-LAST:event_testTreeValueChanged

private void realizarTestButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_realizarTestButtonActionPerformed

    ultimoNodo = (DefaultMutableTreeNode) testTree.getLastSelectedPathComponent();


    Calendar currentTime = Calendar.getInstance();
    Calendar fechaInicio = Calendar.getInstance();
    Calendar fechaFin = Calendar.getInstance();

    if (ultimoNodo != null) {

        if (ultimoNodo.getLevel() == 2) {

            Test test = (Test) ultimoNodo.getUserObject();

            fechaInicio.setTimeInMillis(test.getFechaInicio().getTime());
            fechaFin.setTimeInMillis(test.getFechaFin().getTime());

            if ((currentTime.before(fechaFin) && currentTime.after(fechaInicio)) && (!this.usuario.testRealizado(test))) {

                this.setVisible(false);
                PreguntaFrame preguntas = new PreguntaFrame(test, usuario);
                view.addFrame(preguntas);
                //view.setStatusMessageLabel("¡El test ha comenzado!", Color.black);
                JOptionPane.showMessageDialog(null, Messages.getString("testComenzado", Messages.BUNDLE_NAME_REALIZAR_TEST));

            } else {
                //view.setStatusMessageLabel("No es posible iniciar el test.", Color.red);   
                JOptionPane.showMessageDialog(null, Messages.getString("testInactivo", Messages.BUNDLE_NAME_REALIZAR_TEST),"Error",JOptionPane.ERROR_MESSAGE);
            }

        } 
        else if (ultimoNodo.getLevel() == 1) {
               //view.setStatusMessageLabel("Sólo se pueden iniciar tests. Esto es una asignatura.", Color.red);
            JOptionPane.showMessageDialog(null, Messages.getString("asignaturaSeleccionada", Messages.BUNDLE_NAME_REALIZAR_TEST),"Error",JOptionPane.ERROR_MESSAGE);
        } 
        else if (ultimoNodo.getLevel() == 0) {
               //view.setStatusMessageLabel("Sólo se pueden iniciar tests.", Color.red);
            JOptionPane.showMessageDialog(null,Messages.getString("rootNodeSeleccionado", Messages.BUNDLE_NAME_REALIZAR_TEST),"Error",JOptionPane.ERROR_MESSAGE);
        }
    
    } else {
        //view.setStatusMessageLabel("Primero debe seleccionar un test.", Color.red);
        JOptionPane.showMessageDialog(null,Messages.getString("testNoSeleccionado", Messages.BUNDLE_NAME_REALIZAR_TEST),"Error",JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_realizarTestButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel HoraFinLabel;
    private javax.swing.JLabel HoraInicioLabel;
    private javax.swing.JButton actualizarButton;
    private javax.swing.JPanel consejoPanel;
    private javax.swing.JTextField consejoTextField;
    private javax.swing.JLabel descripcionLabel;
    private javax.swing.JLabel descripcionLabel1;
    private javax.swing.JLabel fechaFinLabel;
    private javax.swing.JLabel fechaFinLabel1;
    private javax.swing.JLabel fechaInicioLabel;
    private javax.swing.JLabel fechaInicioLabel1;
    private javax.swing.JLabel horaFinLabel1;
    private javax.swing.JLabel horaInicioLabel1;
    private javax.swing.JPanel informacionPanel;
    private javax.swing.JLabel numeroPreguntasLabel;
    private javax.swing.JLabel numeroPreguntasLabel1;
    private javax.swing.JButton realizarTestButton;
    private javax.swing.JScrollPane testScrollPane;
    private javax.swing.JTree testTree;
    // End of variables declaration//GEN-END:variables

    private void mostrarInformacion() {
        if (ultimoNodo != null) {
            if (ultimoNodo.getLevel() == 1) {

                this.descripcionLabel1.setText("");
                this.numeroPreguntasLabel1.setText("");
                this.fechaInicioLabel1.setText("");
                this.fechaFinLabel1.setText("");
                this.horaInicioLabel1.setText("");
                this.horaFinLabel1.setText("");

            } else if (ultimoNodo.getLevel() == 2) {

                Test test = (Test) ultimoNodo.getUserObject();

                this.descripcionLabel1.setText(test.getDescripcion());
                this.numeroPreguntasLabel1.setText(Integer.toString(test.getNumPreguntas()));

                //DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                DateFormat dateFormat = Messages.getDateFormat();
                String fechaInicio = dateFormat.format(test.getFechaInicio());
                this.fechaInicioLabel1.setText(fechaInicio);

                //DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");
                String fechaFin = dateFormat.format(test.getFechaFin());
                this.fechaFinLabel1.setText(fechaFin);

                this.horaInicioLabel1.setText(test.getStartHour());
                this.horaFinLabel1.setText(test.getEndHour());
            }
        }
        else {
            this.descripcionLabel1.setText("");
            this.numeroPreguntasLabel1.setText("");
            this.fechaInicioLabel1.setText("");
            this.fechaFinLabel1.setText("");
            this.horaInicioLabel1.setText("");
            this.horaFinLabel1.setText("");
        }
    }
    
    /**
     * Establece lenguaje
     */
    public void setLenguaje() {
        setTitle(Messages.getString("realizarTestFrame.title", Messages.BUNDLE_NAME_REALIZAR_TEST));
        HoraFinLabel.setText(Messages.getString("HoraFinLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        HoraInicioLabel.setText(Messages.getString("HoraInicioLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        actualizarButton.setText(Messages.getString("actualizarButton.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        consejoTextField.setText(Messages.getString("consejoTextField.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        descripcionLabel.setText(Messages.getString("descripcionLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        fechaFinLabel.setText(Messages.getString("fechaFinLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        fechaInicioLabel.setText(Messages.getString("fechaInicioLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        informacionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getString("informacionPanel.border.title", Messages.BUNDLE_NAME_REALIZAR_TEST), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, Messages.getColor("informacionPanel.border.titleColor", Messages.BUNDLE_NAME_REALIZAR_TEST)));
        numeroPreguntasLabel.setText(Messages.getString("numeroPreguntasLabel.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        realizarTestButton.setText(Messages.getString("realizarTestButton.text", Messages.BUNDLE_NAME_REALIZAR_TEST));
        testTree.setBorder(javax.swing.BorderFactory.createTitledBorder(Messages.getString("testTree.border.title", Messages.BUNDLE_NAME_REALIZAR_TEST)));
        
        loadTree();
        mostrarInformacion();
    }
}
